#!/usr/bin/perl -wc

package RFCMail::ESMTP::Object::MaybePath;

use strict;
use base qw(RFCMail::ESMTP::Object::Path);
use Exporter qw(import);
use RFCMail::ESMTP::Grammar::Base qw(PATH_RE);
use RFCMail::ESMTP::Object::Path qw(Path);

our @EXPORT_OK = qw(MaybePath);


sub MaybePath {
    my $self;
    if (not @_ or $_[0] !~ /\A@{[PATH_RE]}\z/o) {
	$self = RFCMail::ESMTP::Object::MaybePath->new();
    }
    else {
	$self = Path(@_);
	bless($self, 'RFCMail::ESMTP::Object::MaybePath');
    }
    return ($self);
}


sub new {
    my $class = shift;
    return ($class->SUPER::new(@_))
	if @_;
    return (bless [], $class);
}


sub is_path {
    my ($self) = @_;
    return (scalar(@$self) >= 2);
}


1;
